package com.duobaoyu.dby.supply.biz.client.boundary.channel;

import com.duobaoyu.dby.channel.adapter.bean.invoice.InvoiceInfo;
import com.duobaoyu.dby.channel.adapter.enums.biz.invoice.InvoiceTypeEnum;
import com.duobaoyu.dby.channel.adapter.service.AbstractSupplyChannelInvoiceService;
import com.duobaoyu.dby.common.core.constant.CommonConstants;
import com.duobaoyu.dby.supply.biz.exception.SupplyChainBizException;
import com.duobaoyu.dby.supply.biz.service.invoice.InvoiceSettingService;
import com.duobaoyu.dby.supply.db.entity.invoice.InvoiceSetting;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName SupplyChainInvoiceConfigService
 * @Description 发票配置
 * @createTime 13:34:00 2023/10/11
 */
@Component
@RequiredArgsConstructor
public class SupplyChainInvoiceConfigService extends AbstractSupplyChannelInvoiceService {

	private final InvoiceSettingService invoiceSettingService;

    @Override
    public InvoiceInfo getInvoiceInfo(String channelCode,String configUniqueKey) {
		if(StringUtils.isNotBlank(configUniqueKey)) {
			SupplyChainBizException.fail("不支持对接渠道配置唯一key设置");
			return null;
		} else {
			InvoiceSetting invoiceSettingCacheByChannelCode = invoiceSettingService.getInvoiceSettingCacheByChannelCode(channelCode);
			if (ObjectUtils.isEmpty(invoiceSettingCacheByChannelCode)) {
				return null;
			}
			InvoiceInfo invoiceInfo = new InvoiceInfo();
			//开票方式(2为集中开票，4 订单完成后开票)
			invoiceInfo.setInvoicePutType(CommonConstants.TWO);
			//1:明细，100：大类 备注:若增值税专用发票则只能选1 明细
			invoiceInfo.setInvoiceType(InvoiceTypeEnum.ELECTRONIC_TICKET.getValue());
			invoiceInfo.setInvoiceSelectedTitle(5);
			invoiceInfo.setInvoiceCompanyName(invoiceSettingCacheByChannelCode.getInvoiceCompanyName());
			invoiceInfo.setInvoiceContentType(CommonConstants.ONE);
			invoiceInfo.setInvoiceName(invoiceSettingCacheByChannelCode.getInvoiceName());
			invoiceInfo.setInvoiceAddress(invoiceSettingCacheByChannelCode.getInvoiceAddress());
			invoiceInfo.setInvoiceRegBank(invoiceSettingCacheByChannelCode.getInvoiceRegBank());
			invoiceInfo.setInvoiceRegCode(invoiceSettingCacheByChannelCode.getInvoiceTaxpayerCode());
			invoiceInfo.setInvoicePhone(invoiceSettingCacheByChannelCode.getInvoicePhone());
			invoiceInfo.setInvoiceAddress(invoiceSettingCacheByChannelCode.getInvoiceAddress());
			invoiceInfo.setInvoiceRegBankAccount(invoiceSettingCacheByChannelCode.getInvoiceRegBankAccount());
			invoiceInfo.setInvoiceRegBank(invoiceSettingCacheByChannelCode.getInvoiceRegBank());
			invoiceInfo.setInvoiceRegPhone(invoiceSettingCacheByChannelCode.getInvoiceRegPhone());
			invoiceInfo.setInvoiceRegAddress(invoiceSettingCacheByChannelCode.getInvoiceRegAddress());
			invoiceInfo.setInvoiceRegCompanyName(invoiceSettingCacheByChannelCode.getInvoiceRegCompanyName());
			invoiceInfo.setInvoiceCityCode(invoiceSettingCacheByChannelCode.getInvoiceCityCode());
			invoiceInfo.setInvoiceCountyCode(invoiceSettingCacheByChannelCode.getInvoiceCountyCode());
			invoiceInfo.setInvoiceProvinceCode(invoiceSettingCacheByChannelCode.getInvoiceProvinceCode());
			invoiceInfo.setInvoiceTownCode(invoiceSettingCacheByChannelCode.getInvoiceTownCode());
			invoiceInfo.setInvoiceTaxpayerCode(invoiceSettingCacheByChannelCode.getInvoiceTaxpayerCode());
			return invoiceInfo;
		}
    }
}
